package game.square;

import game.dungeon.position.Direction;
import game.square.temperature.TemperatureScale;

import java.math.BigDecimal;
import java.util.*;

import be.kuleuven.cs.som.annotate.*;

/**
 * A class of squares, who form the smallest unit of location in the game,
 * storing its temperature, humidity, slipperiness, inhabitability and
 * borders.
 *
 * @version 1.0
 * @author Chris Desomer, Geert Heyman
 */

public class CommonSquare extends TeleportationSquare {
	
	/**
	 * Initialize this new common square with given temperature and humidity.
	 *
	 * @param	temperature
	 *          The temperature for this new common square.
	 * @param	temperatureScale
	 * 			The temperature scale in which the given temperature
	 * 			is expressed.
	 * @param 	humidity
	 * 			The humidity for this new common square.
	 * @param	slipperyMaterial
	 * 			Indicates if this new common square is made of a slippery material.
	 * @param	borderDirections
	 * 			The directions to set borders.
	 * @param	teleportationDestinations
	 * 			The teleportation destinations for this square.
	 * @pre		..
	 * 		  | teleportationDestinations != null
	 * @pre		..
	 * 		  | areValidTeleportationDestinations(teleportationDestinations)
	 * @pre		..
	 * 		  | temperatureScale != null
	 * @pre		..
	 * 		  | humidity != null
	 * @effect	..
	 * 		  | super (temperature, temperatureScale, humidity, slipperyMaterial, teleportationDestinations)
	 * @post	If the given border directions at least contain one effective 
	 * 			direction, then this new common square has a door for each direction in 
	 * 			the set.
	 * 		  |	if (for some direction in Direction : borderDirections.contains(direction))
	 * 		  |		then for each direction in borderDirections
	 * 		  |			new.getBorderInDirection(direction).getClass() == Door.class
	 * @post	Else, this new common square has a door in the north.
	 * 		  |	else new.getBorderInDirection(Direction.NORTH) == Door.class
	 */
	@Raw
	public CommonSquare(int temperature, TemperatureScale temperatureScale,
			BigDecimal humidity, boolean slipperyMaterial,
			Set<Direction> borderDirections,
			List<Square> teleportationDestinations) {
		super (temperature, temperatureScale, humidity, slipperyMaterial, teleportationDestinations);
		if (borderDirections == null)
			borderDirections = new HashSet<Direction>();
		if (borderDirections.isEmpty())
			borderDirections.add(Direction.NORTH);
		placeBorders(borderDirections);
	}
	
	/**
	 * Initialize this new common square as a default common square.
	 * 
	 * @effect 	This new common square is initialized as a default common square with a temperature
	 * 			of 20 in degrees Celcius, a humidity of 15.00%, a not slippery
	 * 			material and no teleportation destinations.
	 * 		  | this (20,TemperatureScale.CELCIUS,BigDecimal.valueOf(1500,2),false, 
	 * 		  |		new HashSet<Direction>(),new ArrayList<Square>()) 
	 */
	@Raw
	public CommonSquare(){
		this (20,TemperatureScale.CELCIUS,BigDecimal.valueOf(1500,2),false,new HashSet<Direction>(),new ArrayList<Square>());
		
	}
	
	/*
	 * Doors are added default.
	 */
	private void placeBorders(Set<Direction> borderDirections) {
		for (Direction direction : borderDirections){
			addBorderInDirection(new Door(), direction);
		}
	}


}
